package org.jetlinks.community.mstn.entity.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hswebframework.web.system.authorization.api.entity.UserEntity;
import org.jetlinks.community.auth.entity.UserDetail;
import org.jetlinks.community.auth.enums.RoleType;
import org.jetlinks.community.auth.service.request.SaveUserRequest;
import org.jetlinks.community.mstn.config.MstnConfig;

import java.util.Collections;
import java.util.HashSet;
import java.util.Map;

@Data
public class MultiTenantCreateReqVO {

    @Schema(description = "用户ID")
    private String userId;

    @Schema(description = "联系人")
    private String name;

    @Schema(description = "联系人手机号,可为空")
    private String telephone;

    @Schema(description = "用户账号")
    private String username;


    @Schema(description = "密码")
    private String password;


    public UserDetail getUserDetail(){
        UserDetail detail = new UserDetail();
        detail.setId(getUserId());
        detail.setUsername(getUsername());
        detail.setPassword(getPassword());
        detail.setType(RoleType.multiTenant.getValue());
        detail.setName(getName());
        detail.setTelephone(getTelephone());
        return detail;
    }


    public SaveUserRequest getSaveUserRequest(){
        SaveUserRequest request = new SaveUserRequest();
        request.setRoleIdList(new HashSet<>(Collections.singletonList(MstnConfig.getTenantRoleId())));
        request.setUser(getUserDetail());
        return request;
    }
}
